1. /* sdcchpi.cpp by K.Tsuru */
  2. // ver. 2.30
  3. // function ID 3555 DRADIX
  4. /***************************************************************
  5. SN library
  6. An evaluation of pi by the binary splitting method using Chudnovskys' formura.
  7. 1 1 \prod_{k=0}^(n-1) {-(2k+1)(6k+1)(6k+5)}
  8. ---- = -------------------sum_{n=0]^{L}-------------------------------------------- (A+B*n)
  9. pi 426880*sqrt(10005) \prod_{k=0}^n {(C*k)^3}/24 (k>=1)
  10. where A = 13591409, B = 545140134, C = 640320 and C^(1.5)/12=426880*sqrt(10005). See below about "L".
  11. Let
  12. 426880*sqrt(10005)
  13. --------------------- = sum_{k=0]^{L}P(k)
  14. pi
  15. P(k+1) -24(6k+1)(2k+1)(6k+5)(A+Bk+B)
  16. ------ = ---------------------------
  17. P(k) C^3(k+1)^3(A+Bk)
  18. P(k+1)
  19. \lim_{k \to \infty}------ = -24*(6^2*2)/C^3 = -1/15193 13730 56000 = -1/Q
  20. P(k)
  21. (i)log10(Q) = 14.18...
  22. P(1) A+B
  23. ---- = -120*(A+B)/(A*C^3) = - ------------------- = - 1/Q0
  24. P(0) 2187811772006400*A
  25. 13591409
  26. (ii)Q0 = 2187811772006400----------- = 5321 95559 40398.61289....
  27. 558731543
  28. log10(Q0) = 13.726...
  29. Then adding one term the precision raises up about 14 digits.
  30. The upper limit "L" may be chosen L= (the effective number of digits)/14.
  31. ---- 32bit SLong version ----------------
  32. Binary Splitting method Nov.19,2016
  33. CPU Core i7-3770 3.4GHz Memory 32.0GB
  34. digits | CPU time(sec)
  35. 4000069 | 21.0
  36. 8000029 | 46.75
  37. 33550029 | 233.121 (33 million)
  38. 50000029 | 372.56[6min 12sec]
  39. 100000029 |1140[19min]+output= 12(sec)(100 millon)
  40. ---- 64bit SDouble version ----------------
  41. digits | CPU time(sec)
  42. 500000 | 1.78949(sec)
  43. 50000028 | 442.53(sec) [7.3755 min]
  44. ***************************************************************/
  45. #ifndef SN_H
  46. #include "sn.h"
  47. #endif
  48. static const double upPerTerm = 14.18;
  49. #define CH_PI_SLONG 0
  50. #if CH_PI_SLONG
  51. ////// SLong version /////// 1.75(sec) 500029 digits
  52. class BSChudnovskysPi : public BinarySplitting<SLong> {
  53. public:
  54. /* Constructer : 'L' is upToTerm, 'f' is precision*/
  55. BSChudnovskysPi(long L, long f) : BinarySplitting<SLong>(L, f){}
  56. void setABC(long k, SLong& a, SLong& b, SLong& c) {
  57. static const SLong tA(13591409L);
  58. static const SLong tB(545140134L);
  59. static const SLong tC(640320L);
  60. static const SLong tC3((tC * tC * tC)/24L);
  61. a = tA + tB * k;
  62. // B(k) = - (2 * k + 1) *(6 * k + 1) * (6 * k + 5)
  63. long p = - (2L * k + 1L), q = 6L * k + 1L, r = 6L * k + 5L;
  64. b = p; b *= q; b *= r;
  65. // C(0) = 1, C(k) = tC3 * k^3(k >= 1)
  66. if(k == 0) c = 1;
  67. else {
  68. c = k; c *= (c*c); c *= tC3;
  69. }
  70. }
  71. SDouble getValue() {
  72. putTogether();
  73. SDouble pi = BinarySplitting<SLong>::getValue(true);
  74. A=0.0; B= 0.0; C=0.0; // free memory
  75. SDouble a = Sqrt(10005L);
  76. a *= 426880L;
  77. pi *= a;
  78. return pi;
  79. }
  80. };
  81. SDouble ChudnovskysPi() {
  82. SDouble tmp;
  83. long f = long(tmp.EffFig() + tmp.Hidden()+ 1u)*DFIGURES;
  84. long L = (long)((double)f/upPerTerm);
  85. BSChudnovskysPi pi(L, f);
  86. return pi.getValue();
  87. }
  88. #else
  89. ////// SDouble version /////// 4.92(sec) 500029 digits
  90. class BSChudnovskysPi : public BinarySplitting<SDouble> {
  91. public:
  92. BSChudnovskysPi(long L, long f) : BinarySplitting<SDouble>(L, f){}
  93. void setABC(long k, SDouble& a, SDouble& b, SDouble& c) {
  94. static const SDouble A(13591409L);
  95. static const SDouble B(545140134L);
  96. static const SDouble C(640320L);
  97. static const SDouble C3((C * C * C)/24L);
  98. a = A + B * k;
  99. // B(k) = - (2 * k + 1) *(6 * k + 1) * (6 * k + 5)
  100. long p = - (2L * k + 1L), q = 6L * k + 1L, r = 6L * k + 5L;
  101. b = p; b *= q; b *= r;
  102. // C(0) = 1, C(k) = C3 * k^3
  103. if(k == 0) c = 1;
  104. else {
  105. c = k; c *= (c*c); c *= C3;
  106. }
  107. }
  108. SDouble getValue() {
  109. putTogether();
  110. SDouble pi = BinarySplitting<SDouble>::getValue(true), a = Sqrt(10005L);
  111. pi *= a;
  112. pi *= 426880L;
  113. return pi;
  114. }
  115. };
  116. SDouble ChudnovskysPi() {
  117. SDouble tmp;
  118. long f = long( tmp.EffFig() + tmp.Hidden() ), L = (long)((double)f / 2);
  119. BSChudnovskysPi pi(L, f);
  120. return pi.getValue();
  121. }
  122. #endif

sdcchpi.cpp : last modifiled at 2017/04/12 15:08:00(4,238 bytes)
created at 2017/10/07 10:21:15
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).